//
//  YXTabBar.swift
//  微博YX
//
//  Created by apple on 15/11/23.
//  Copyright © 2015年 lyx. All rights reserved.
//

import UIKit

class YXTabBar: UITabBar {

    override func layoutSubviews() {
        //    计算宽度
        let width = bounds.size.width / 5
        //        获得frame
        let frame = CGRect(x: 0, y: 0, width: width , height: bounds.size.height)
        //        用来标记的索引
        var index = 0
        for view in self.subviews {
            if view is UIControl && !(view is UIButton){
                //                计算tab的位置
                view.frame = CGRectOffset(frame, CGFloat(index) * width, 0)
            }
            //            如果是第一个就让它加2  空出中间的位置
            index += index == 1 ? 2 :1
        }
        composeButton.frame = CGRectOffset(frame, 2 * width, 0)
    }
    
    //    懒加载创建中间的按钮
    lazy var composeButton: UIButton = {
        
        let button = UIButton()
        //       设置图片
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(button)
        return button
        }()
    
    
    
    
    
    
    
    
    
    
    
    
    

}
